package rpc2.handler;

import rpc2.client.DefaultFuture;
import com.alibaba.fastjson.JSON;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import rpc2.param.Response;

public class SimpleClientHandler extends ChannelInboundHandlerAdapter {

        @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            if ("ping".equals(msg.toString())){
                ctx.channel().writeAndFlush("pong\r\n");
                return;
            }
            System.out.println("进来到SimpleClientHandler这里面来了");
//            ctx.channel().attr(AttributeKey.valueOf("sssss")).set(msg);
            System.out.println(msg.toString());
            Response response= JSON.parseObject(msg.toString(),Response.class);
            System.out.println("打印response信息"+response.toString());
            DefaultFuture.receive(response);
//            ctx.channel().close();
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        super.userEventTriggered(ctx, evt);
    }
}
